package com.itheima.mybatis02.service;

import com.itheima.mybatis02.bean.Classes;
import com.itheima.mybatis02.bean.Student;
import com.itheima.mybatis02.dao.ClassesMapper;
import com.itheima.mybatis02.dao.ClassesMapperTest;
import com.itheima.mybatis02.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class ClassesService {
    @Test
    public void select() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        ClassesMapper mapper = sqlSession.getMapper(ClassesMapper.class);
        List<Classes> classes = mapper.selectAll();
        for (Classes aClass : classes) {
            System.out.println(aClass);
        }
    }

    @Test
    public void selectAll2() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        ClassesMapper mapper = sqlSession.getMapper(ClassesMapper.class);
        List<Classes> classes = mapper.selectAll2();
        for (Classes aClass : classes) {
            System.out.println(aClass);

        }
    }

    @Test
    public void seleById(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        ClassesMapperTest mapperTest = sqlSession.getMapper(ClassesMapperTest.class);
        List<Classes> classes = mapperTest.selectAll();
        for (Classes aClass : classes) {
            System.out.println(aClass.getId());
            System.out.println(aClass.getName());
            List<Student> students = aClass.getStudents();
            for (Student student : students) {
                System.out.println(student);
            }
        }
    }
}
